<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="主体名称" prop="marketInfoId">
        <el-input v-model="queryParams.marketInfoId" placeholder="请输入主体名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="所属区域" prop="areaId">
        <el-select v-model="queryParams.areaId" placeholder="请选择所属区域" clearable>
          <el-option v-for="dict in areaList" :key="dict.id" :label="dict.areaName" :value="dict.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="所属市场" prop="affiliationId">
        <el-select v-model="queryParams.affiliationId" placeholder="请选择所属市场" clearable>
          <el-option v-for="dict in affiliationList" :key="dict.id" :label="dict.affiliationName" :value="dict.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="检查试剂" prop="checkReagent">
        <el-input v-model="queryParams.checkReagent" placeholder="请输入检查试剂" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="数据来源" prop="dataSourceId">
        <el-select v-model="queryParams.dataSourceId" placeholder="请选择数据来源" clearable size="small">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.DATA_SOURCE_TYPE)" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="检测结果" prop="checkResult">
        <el-select v-model="queryParams.checkResult" placeholder="请选择检测结果" clearable size="small">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.CHECK_RESULT)" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="样本类型" prop="simpleTypeId">
        <el-select v-model="queryParams.simpleTypeId" placeholder="请选择样本类型" clearable>
          <el-option v-for="dict in productList" :key="dict.id" :label="dict.name" :value="dict.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="样本子类" prop="simpleTowLevelId">
        <el-select v-model="queryParams.simpleTowLevelId" placeholder="请选择样本子类" clearable>
          <el-option v-for="dict in parentList" :key="dict.id" :label="dict.name" :value="dict.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="样品" prop="simpleId">
        <el-select v-model="queryParams.simpleId" placeholder="请选择样品" clearable>
          <el-option v-for="dict in threeList" :key="dict.id" :label="dict.name" :value="dict.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="检查项目" prop="checkType">
        <el-select v-model="queryParams.checkType" placeholder="请选择检查项目" clearable size="small">
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.CHECK_TYPE)" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="采样时间" prop="sampleTakeDate">
        <el-date-picker v-model="queryParams.sampleTakeDate" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item label="检测时间" prop="sampleCheckDate">
        <el-date-picker v-model="queryParams.sampleCheckDate" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
          v-hasPermi="['market:check-data:create']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          :loading="exportLoading" v-hasPermi="['market:check-data:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <!-- <el-table-column label="主键" align="center" prop="id" /> -->
      <el-table-column label="主体名称" align="center" prop="marketName" />
      <!-- <el-table-column label="采样时间" align="center" prop="sampleTakeDate" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.sampleTakeDate) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="检测时间" align="center" prop="sampleCheckDate" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.sampleCheckDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检查试剂" align="center" prop="checkReagent" />
      <el-table-column label="数据来源" align="center" prop="dataSourceId">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.DATA_SOURCE_TYPE" :value="scope.row.dataSourceId" />
        </template>
      </el-table-column>
      <el-table-column label="检测结果" align="center" prop="checkResult">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.CHECK_RESULT" :value="scope.row.checkResult" />
        </template>
      </el-table-column>
      <el-table-column label="样本类型" align="center" prop="simpleTypeName" />
      <el-table-column label="样本子类" align="center" prop="simpleTowLevelName" />
      <el-table-column label="样品名称" align="center" prop="simpleName" />
      <el-table-column label="检查项目" align="center" prop="checkType" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)"
            v-hasPermi="['market:check-data:update']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['market:check-data:delete']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 对话框(添加 / 修改) -->
    <CheckDataForm ref="formRef" @success="getList" />
  </div>
</template>

<script>
import * as CheckDataApi from '@/api/market/CheckData';
import CheckDataForm from './CheckDataForm.vue';
import * as ProductLevelThreeApi from '@/api/market/ProductLevelThree';
import * as ProductTypeApi from '@/api/market/ProductType';
import * as ProductLevelTowApi from '@/api/market/ProductLevelTow';
import * as AreaCategoryApi from '@/api/market/AreaCategory';
import * as AffiliationCategoryApi from '@/api/market/AffiliationCategory';
export default {
  name: "CheckData",
  components: {
    CheckDataForm,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检测日志列表
      list: [],
      productList:[],
      parentList:[],
      threeList:[],
      areaList: [],
      affiliationList: [],
      // 是否展开，默认全部展开
      isExpandAll: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 选中行
      currentRow: {},
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        marketInfoId: null,
        sampleTakeDate: [],
        sampleCheckDate: [],
        checkReagent: null,
        dataSourceId: null,
        createTime: [],
        checkResult: null,
        simpleTypeId: null,
        simpleTypeName: null,
        simpleTowLevelId: null,
        simpleTowLevelName: null,
        simpleId: null,
        simpleName: null,
        checkType: null,
        checkType: null,
        areaId: null,
        affiliationId: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    async getList() {
      try {
        this.loading = true;
        const res = await CheckDataApi.getCheckDataPage(this.queryParams);
        this.list = res.data.list;
        const list = await ProductTypeApi.getProductTypeList();
        const parentList = await ProductLevelTowApi.getProductLevelTowList();
        const threeList = await ProductLevelThreeApi.getProductLevelThreeList();
        this.parentList = parentList.data
        this.threeList = threeList.data
        this.productList = list.data
        this.total = res.data.total;
        const areaList = await AreaCategoryApi.getAreaCategoryList();
        this.areaList = areaList.data
        const affiliationList = await AffiliationCategoryApi.getAffiliationCategorylist();
        this.affiliationList = affiliationList.data
      } finally {
        this.loading = false;
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 添加/修改操作 */
    openForm(id) {
      this.$refs["formRef"].open(id);
    },
    /** 删除按钮操作 */
    async handleDelete(row) {
      const id = row.id;
      await this.$modal.confirm('是否确认删除检测日志编号为"' + id + '"的数据项?')
      try {
        await CheckDataApi.deleteCheckData(id);
        await this.getList();
        this.$modal.msgSuccess("删除成功");
      } catch { }
    },
    /** 导出按钮操作 */
    async handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有检测日志数据项?').then(() => {
        this.exportLoading = true;
        return CheckDataApi.exportCheckDataExcel(queryParams);
      }).then(response => {
        this.$download.excel(response, '检测日志.xls');
        this.exportLoading = false;
      }).catch(() => { });
    },

  }
};
</script>
